package org.example.task.controller;


import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.example.task.model.dto.taskassignment.TaskAssignDTO;
import org.example.task.model.vo.R;
import org.example.task.service.ITaskAssignmentService;
import org.example.task.service.ITaskService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 任务分配模块
 *
 * @module 任务分配模块
 */
@RestController
@RequestMapping("/task-assignment")
@RequiredArgsConstructor
public class TaskAssignmentController {
    private final ITaskAssignmentService taskAssignmentService;

    /**
     * 分配任务
     * @param taskAssignDTO 请求数据
     * @return 结果
     */
    @PreAuthorize("hasAuthority('task_assign')")
    @PostMapping
    public R assign(@Valid @RequestBody TaskAssignDTO taskAssignDTO){
        boolean flag = taskAssignmentService.assignTask(taskAssignDTO);
        if(flag){
           return R.success();
        }
        return R.error("分配失败");
    }
}
